/**
 * 
 */
package br.com.fatesg.www.dao;

import org.hibernate.Query;
import org.hibernate.Session;

import br.com.fatesg.www.entidade.Industria;
import br.com.fatesg.www.util.HibernateUtil;

/**
 * @author eder
 * 
 */
public class IndustriaDAO extends DAO<Industria, Long> {

	Session session;

	public IndustriaDAO(Session session) {
		super(session);
		this.session = session;
	}

	public Session getSession() {
		return session;
	}



	/*public Long salvar(Industria industria) {

		session.beginTransaction();
		Long id = super.salvar(industria);
		session.getTransaction().commit();
		session.flush();
		session.close();

		return id;
	}

	public void atualizar(Industria industria) {
		session.beginTransaction();
		super.atualizar(industria);
		session.getTransaction().commit();
		session.flush();
		session.close();
	}

	public void excluir(Industria industria) {
		session.beginTransaction();
		super.excluir(industria);
		session.getTransaction().commit();
		session.flush();
		session.close();
	}

	@SuppressWarnings("rawtypes")
	public List<Industria> listar(Class clazz) {
		if (!session.isOpen()) {
			session = HibernateUtil.getSessionFactory().openSession();
			super.session = session;
		}
		return super.listar(clazz);
	}*/
	public Industria obter(Long cnpj) {
		if (!session.isOpen()) {
			session = HibernateUtil.getSessionFactory().openSession();
		}
		Query query = session.createQuery("from Industria where cnpj = :cnpj");
		query.setParameter("cnpj", cnpj);
		query.setMaxResults(1);
		return (Industria) query.uniqueResult();
	}


}
